import * as alarmDataService from '@/services/alarmData';

export default {
  namespace: 'alarmData',
  state: {
    h: '',
    list: [],
    total: 0,
    pageNo: 1,
    pageSize: 5,
  },
  reducers: {
    setData(state, { payload }) {
      return { ...state, ...payload };
    },
  },
  effects: {
    *fetch({ payload: { h, pageNo } }, { call, put, select }) {
      const pageSize = yield select(state => state.alarmData.pageSize);
      h = h?h:yield select(state => state.alarmData.h);
      const response = yield call(alarmDataService.getRealAlarmData, { h, pageNo, pageSize });
      if (response && typeof response.state !== undefined && response.state === 0) {
        yield put({ type: 'setData', payload: { ...response.data, h, pageNo } });
      } else {
        yield put({
          type: 'setData',
          payload: { h:'', list:[], total:0 },
        });
      }
    },
    *ackAllAlarm({ payload }, { call }) {
      return yield call(alarmDataService.ackAllAlarm, payload);
    }
  }
}
